const mysql = require('mysql2');

module.exports = (req,res,next)=>{
  const conn = mysql.createConnection({
    host:'127.0.0.1',
    port:'3306',
    user:'root',
    password:'',
    database:'lcf172'
  });
  //每分钟访问数据库一次，这样数据库连接就不会断开
  setInterval(() => {
    conn.query('select 1', (error, result) => {
      console.log(result)
    })
  }, 1000 * 60);
  req.db = conn.promise();
  
  next();
}